package com.company.ems.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UpdatePasswordUtil {
    
    public static void main(String[] args) {
        System.out.println("开始更新管理员密码...");
        
        Connection conn = null;
        PreparedStatement pstmt = null;
        
        try {
            conn = DatabaseUtil.getConnection();
            String sql = "UPDATE users SET password = ? WHERE username = ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, "admin123");  // 新密码
            pstmt.setString(2, "admin");     // 用户名
            
            int rowsAffected = pstmt.executeUpdate();
            
            if (rowsAffected > 0) {
                System.out.println("✓ 密码更新成功！");
                System.out.println("用户名: admin");
                System.out.println("新密码: admin123");
            } else {
                System.out.println("✗ 未找到指定用户或更新失败");
            }
            
        } catch (SQLException e) {
            System.err.println("✗ 数据库操作异常: " + e.getMessage());
            e.printStackTrace();
        } finally {
            DatabaseUtil.closeConnection(conn, pstmt);
        }
    }
}